/*
 * @Author: C.
 * @Date: 2023-06-12 10:26:44
 */
// import { ref } from 'vue';
import { ref, computed, unref, watch } from 'vue';
type IStatus = 'error' | 'modified' | 'normal' | 'warning';
const statusMap = {
  error: 'red',
  modified: '#059669',
  normal: false,
  warning: 'yellow',
};
export function useCellStatus({ defaultValueRef, currentValueRef }) {
  const statusRef = ref<IStatus>('normal');
  const statusColor = computed(() => {
    return statusMap[unref(statusRef)];
  });
  function setCellStatus(status: IStatus) {
    statusRef.value = status;
  }
  watch(
    () => unref(currentValueRef),
    (newData) => {
      if (unref(defaultValueRef) !== newData) {
        setCellStatus('modified');
      } else {
        setCellStatus('normal');
      }
    },
  );
  return {
    statusColor,
    setCellStatus,
  };
}
